<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>fieldFilter</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1" name="viewport" />
    <meta content="Preview page of Metronic Admin Theme #1 for form layouts" name="description" />
    <meta content="" name="author" />

    <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../../global/plugins/datatables/plugins/bootstrap/datatables.bootstrap.css" />
    <link href="../../global/css/components.min.css" rel="stylesheet" id="style_components" type="text/css" />
    <link href="../../global/css/plugins.min.css" rel="stylesheet"  type="text/css" />
    <link rel="stylesheet" href="layui/css/layui.css"/>
    <link rel="stylesheet" href="../../custom/css/changeother.css"/>
<body>
<div class="contentPadding">
    <table class="layui-table" id="LAY_table_user" lay-filter="user"></table>
</div>

<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="../../global/plugins/datatables/datatables.min.js"></script>
<script src="js/bootstrap.min.js" type="text/javascript"></script>
<script src="layui/layui.all.js"></script>
<script src="js/template.js"></script>
<script>
    console.log(parent.currentFields);
    console.log(parent.currentSelectedFields);
   console.log(parent.currentIsEnglish);
    (function () {
       	var selectFields;
        //字段转换成表格数据
        var data = $.map(parent.currentFields,function (v,i) {
            
        	var fieldName;
        	//如果当前元素显示英文
        	if(parent.currentIsEnglish){
        		fieldName = v.columnName;
        		
        		selectFields = $.map(parent.currentSelectedFields,function(v,i){
        			return v.columnName
        		})
        		
        	}else {
        		fieldName = v.columnChname;
        		
        		selectFields = $.map(parent.currentSelectedFields,function(v,i){
        			return v.columnChname
        		})
        	}
        	
        	
        	 var flag;
             if( selectFields.indexOf(fieldName) === -1){
                 flag = false;
             }else {
                 flag = true;
             }
            
            return {"fieldName" : fieldName ,"LAY_CHECKED": flag, "allColumnName":{"columnName":v.columnName,"columnChname":v.columnChname}}
        });
	console.log(data)
        layui.use('table', function(){
            var table = layui.table;
            //方法级渲染
            table.render({
                elem: '#LAY_table_user'
                ,cols: [[
                    {type:'checkbox'}
                    ,{field:'fieldName', title: '字段名', minWidth:80,}
                ]]
                ,id: 'testReload',
                height: 'full-20',
                data : data,
                limit:100000
                ,done :function(){

                }
            });
         //表格数据转换成字段数据
         window.getCheckFieldData = function () {
        var checkStatus = table.checkStatus('testReload'); //test即为基础参数id对应的值
        console.log(checkStatus.data); //获取选中行的数据

        var fieldSelected = $.map(checkStatus.data,function (v,i) {
           return v.allColumnName;
        });
        console.log(fieldSelected);
        return fieldSelected;
    };

        });

    })();

</script>
</body>

</html>